<!DOCTYPE html>
<html>
<head>
    <title>管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="搜索名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <#if shiro.hasPermission("app:jobapply:")>
        <button class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加 </button>
        </#if>
    </div>
</script>
<script type="text/html" id="currentStatusTpl">
    {{# if(d.status == 0){ }}
    <span class="layui-badge layui-bg-green">已提交申请</span>
    {{# } else if(d.status == 10){ }}
    <span class="layui-badge layui-bg-green">已录用</span>
    {{# } else if(d.status == 20){ }}
    <span class="layui-badge layui-bg-gray">被拒绝</span>
    {{# } else if(d.status == 21){ }}
    <span class="layui-badge layui-bg-gray">申请人取消</span>
    {{# } else if(d.status == 22){ }}
    <span class="layui-badge layui-bg-gray">兼职消息已删除</span>
    {{# } else if(d.status == 30){ }}
    <span class="layui-badge layui-bg-green">待评论</span>
    {{# } else if(d.status == 40){ }}
    <span class="layui-badge layui-bg-green">已评论</span>
    {{# } else { }}
    <span></span>
    {{# } }}
</script>

<script type="text/html" id="currentTableTypeTpl">
    {{# layui.each(d.label, function(index, item){ }}
    <span class="layui-badge-rim">{{item}}</span>
    {{# }); }}
</script>
<script type="text/html" id="currentDeletedpl">
    {{# if(d.status == 0){ }}
    <span class="layui-badge layui-bg-green">启用</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-grey">删除</span>
    {{# } }}
</script>
<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:jobapply:")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </#if>
    <#if shiro.hasPermission("app:jobapply:delete")>
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </#if>
</script>

<script>
    var formDataId = 0;
    layui.use(['table'], function () {
        var $ = layui.jquery,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('jobapply/list'),
             toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [[
                {type: "numbers", width: 80},
                {field: 'jobId', minWidth: 100, title: '兼职'},
                {field: 'userId', minWidth: 100, title: '用户'},
                {field: 'status', minWidth: 200, title: '状态',templet: '#currentStatusTpl'},
                {field: 'deleted', minWidth: 100, title: '逻辑删除',templet: '#currentDeletedpl'},
                {field: 'createTime', minWidth: 100, title: '创建时间'},
                {field: 'updateTime', minWidth: 100, title: '修改时间' ,},
                {title: '操作', width: 120, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [15, 30, 50],
            limit: 15,
            page: true
        });

        initSearchForm('searchForm', 'currentTableId');
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                formDataId = 0;
                openFormView('app/jobapply/form.html', '添加兼职申请人');

            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/jobapply/form.html', '编辑兼职申请人');
                return false;
            }else if (obj.event === 'delete') {
                layer.confirm('确定删除 '+data.introduction+' 吗？', function (index) {
                    deleteTableRow('jobapply/delete/', [data.id], function (rs) {
                    	obj.del();
                    });
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>